﻿using System;
using System.Collections.Generic;

namespace VIT.Web.Modules.Products
{
    public partial class Products : VIT.Web.UI.VITModule
    {
        public string catId
        {
            get { return Convert.ToString(ViewState["catId"]); }
            set { ViewState["catId"] = value; }
        }
        private string ColorId
        {
            get { return string.IsNullOrEmpty(Page.Request.Params.Get("sColorsId")) ? "0" : Page.Request.Params.Get("sColorsId"); }
        }
        private string StyleId
        {
            get { return string.IsNullOrEmpty(Page.Request.Params.Get("sStylesId")) ? "0" : Page.Request.Params.Get("sStylesId"); }
        }
        private string CatID
        {
            get { return string.IsNullOrEmpty(Page.Request.Params.Get("CatID")) ? "0" : Page.Request.Params.Get("CatID"); }
        }
        private string PageSize
        {
            get { return (Params as Dictionary<string, string>).ContainsKey("PageSize") ? Params["PageSize"] : "8"; }
        }

        public dynamic Obj; public int isColor;

        private void loadChoose()
        {
            if (ColorId == "0" && StyleId == "0") isColor = 0;
            else if (ColorId != "0")
            {
                isColor = 1;
                Obj = ColorId;
            }
            else // StyleId != "0"
            {
                isColor = 2;
                Obj = StyleId;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Pager.PageSize = Convert.ToInt32(PageSize);
            }
            //if (!IsPostBack)
            //{
            //    ProductProvider p = new ProductProvider();
            //    p.LanguageId = Session["language"].ToString();
            //    rpt.DataSource = p.getTopViewProduct(Params, ref catId);
            //    rpt.DataBind();
            //}
        }

        protected void Pager_PreRender(object sender, EventArgs e)
        {
            loadChoose();
            ProductProvider p = new ProductProvider();
            p.LanguageId = Session["language"].ToString();
            string cId = string.Empty;
            catId = cId;
            //Pager.PageSize = Convert.ToInt32(PageSize);
            ListView.DataSource = p.getTopViewProduct(Params, ref cId);
            ListView.DataBind();
        }

        protected void lbtViewAll_Click(object sender, EventArgs e)
        {
            Pager.SetPageProperties(0, 100, false);
            Pager.PageSize = 100;
            ListView.DataBind();
            System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "lbtViewAll_Click",
                "$(document).ready(function () {if (document.getElementById('go" + catId + "') != null){scrollTo(document.getElementById('go" + catId + "').parentNode.parentNode.offsetLeft, document.getElementById('go" + catId + "').parentNode.parentNode.offsetTop);}});", true);
        }
    }
}